﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using GameCore;
using HandlingInput;

namespace GameObject
{
    public class Avatar : VisibleGameObject
    {
        List<string> l_infor_sprite;
        List<Vector2> l_position_message;

        int _n_message;

        public int n_message
        {
            get { return _n_message; }
            set { _n_message = value; }
        }

        private float blood;

        public float Blood
        {
            get { return blood; }
            set { blood = value; }
        }

        Vector2 position_Blood;

        private SpriteFont _font;

        public SpriteFont Font
        {
            get { return _font; }
            set { _font = value; }
        }

        public bool Init(int _numberSprite, string[] strResource, int nmessage, List<string> infor_avatar, List<Vector2> position_sprite, List<Vector2> position_message, float blood, Vector2 positionBlood, Microsoft.Xna.Framework.Graphics.SpriteFont font)
        {
            Font = font;
            _nsprite = _numberSprite;
            _sprite = new Sprite[_nsprite];
            _lsprite = new List<Vector2>();
            l_infor_sprite = new List<string>();
            l_position_message = new List<Vector2>();
            position_Blood = positionBlood;

            l_infor_sprite = infor_avatar;
            l_position_message = position_message;
            n_message = nmessage;

            for (int i = 0; i < _nsprite; i++)
            {
                Texture2D[] texture = new Texture2D[strResource.Length];
                for (int j = 0; j < strResource.Length; j++)
                {
                    texture[j] = GlobalDefine.Content.Load<Texture2D>(@"Pictures/" + strResource[j]);
                }
                _sprite[i] = new Sprite(0, 0, 0, 0, texture);
                _sprite[i].x = position_sprite[i].X;
                _sprite[i].y = position_sprite[i].Y;

            }
            return true;
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, float x, float y, int w, int h)
        {
            base.Update(gameTime, x, y, w, h);
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            for (int i = 0; i < _lsprite.Count; i++)
            {
                if (_lsprite[i].X < _sprite.Count<Sprite>())
                {
                    _sprite[(int)_lsprite[i].X].Draw(gameTime, spriteBatch);
                }
            }
            for (int i = 0; i < l_infor_sprite.Count; i++)
            {
                spriteBatch.DrawString(Font, l_infor_sprite[i], l_position_message[i], Color.White);
            }

            spriteBatch.DrawString(Font, Blood.ToString(), position_Blood , Color.Green);
        }

        public override VisibleGameObject Clone()
        {
            return base.Clone();
        }
    }
}
